package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.dto.DishDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/category")
@Slf4j
@Api(tags = "菜品及套餐分类管理接口")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @PostMapping
    public Result save(@RequestBody CategoryDTO categoryDTO) {
        categoryService.inster(categoryDTO);
        return Result.success();

    }

    @GetMapping("/{page}")
    public Result Selectid(CategoryPageQueryDTO categoryPageQueryDTO) {
        PageResult pageResult = categoryService.selectid(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    @DeleteMapping
    public Result delete(Long id) {
        categoryService.delete(id);
        return Result.success();
    }
    @PutMapping
    public Result update(@RequestBody CategoryDTO categoryDTO){
        categoryService.update(categoryDTO);
        return Result.success();
    }
    @PostMapping("/status/{status}")
    public Result stopstart(@PathVariable Integer status,Long id){
        categoryService.stopstart(status,id);
        return Result.success();
    }
    @GetMapping("/list")
    public Result list(Integer type){
       List<Category> categoryList= categoryService.select(type);
        return Result.success(categoryList);
    }

}


